import math
import numpy as np


def uniform_distribution(n: int, x: int) -> float:  # 离散均匀分布
    return 1/n


def shannon_Entropy(n: int, distribution: function) -> float:  # 离散香农熵
    px = np.ndarray([distribution(n, x) for x in range(1, n+1)])
    log2_px = np.ndarray([math.log2(x) for x in px])

    return -np.dot(np, log2_px.T)


if __name__ == "__main__":
    print(shannon_Entropy(32, uniform_distribution))
